//检测参数是否为数字
function ifDigit(str)
{
   slen=str.length;
   for (i=0; i<slen; i++){
      cc = str.charAt(i);
      if (cc <"0" || cc >"9")
      {
         return false;
      }
   }
   return true;
}

//检测参数是否为金钱
function ifMoney(str)
{
   slen=str.length;
   if(slen<=0){return false;}
   var money = str.replace(".","");//替换小数点(仅替换1个)
   if(ifDigit(money) == false){//非数字
      return false;
   }
   return true;
}

//检测号码是否手机号码
function ifMobile(str)
{
   if(ifDigit(str) == true){//如果ifDigit检查返回true
      var left3 = str.substring(0,2);
      if(left3 == "13" || left3 == "15"){//如果长度是11位
         if(str.length != 11) {
            return false;
         }else{
            return true;
         }
      }else{
         return false;
      }
   }else{
      return false;
   }
}
//检测号码是否联通号码
function ifUnicom(str)
{
   if(ifDigit(str) == true){//如果ifDigit检查返回true
      if(str.length == 11){//如果长度是11位
         var left3 = str.substring(0,3);
         if(left3 == "130" || left3 == "131" || left3 == "132" || left3 == "155" || left3 == "156"|| left3 == "186"){
            return true;
         }else{
            return false;
         }
      }else{
         return false;
      }
   }else{
      return false;
   }
}

function changeBgcolor1(trname){
   if(document.getElementById(trname) != null){
      document.getElementById(trname).style.backgroundColor = "#8B8B8B";
   }
}

function changeBgcolor2(trname){
   if(document.getElementById(trname) != null){
      document.getElementById(trname).style.backgroundColor = "#ABABAB";
   }
}

function gbcount(message,total,used,remain)
{
   var max;
   max = total.value;
   if (message.value.length > max) {
      message.value = message.value.substring(0,max);
      used.value = max;
      remain.value = 0;
      alert("内容不允许超过"+max+"个字!");
   }else{
      used.value = message.value.length;
      remain.value = max - used.value;
   }
}

function addmessage(obj,str) {
   if(document.getElementById(obj) != null){//判断对象是否存在
      document.getElementById(obj).value = document.getElementById(obj).value + str;
      document.getElementById(obj).focus();
   }
}
function ifNum(str)
{
   if(ifDigit(str) == true){
      var left3 = str.substring(0,2);
      if(left3 == "13" || left3 == "15"){
         if(str.length != 11) {
            return false;
         }else{
            return true;
         }
      }else{
         return true;
      }
   }else{
      return false;
   }
}
function getTime(str)
{
   var slen=str.length;
   var theyear=str.substring(0,4);
   if(slen == 8){
      themonth = "0" + str.substring(5,6);
      theday = "0" + str.substring(7);
   }else if(slen == 9){
      if(str.substring(6,7) == "-"){
         themonth = "0" + str.substring(5,6);
         theday = str.substring(7);
      }else{
         themonth = str.substring(5,7);
         theday = "0" + str.substring(8);
      }
   }else{//如果长度为10
      themonth = str.substring(5,7);
      theday = str.substring(8);
   }  
   return theyear+themonth+theday;
}

function getDiffTime(begintime,diff)//传入开始时间和间隔，返回新时间
{
   //write by qinli 20080605
   //begintime格式为2008-5-6或者2008-05-06都可以，但不可以为20080506
   //如果diff中包含YY,表示间隔为年;包含MM间隔为月;包含DD间隔为日;包含WW间隔为周
   var begint = begintime.split("-");//根据-间隔符分成数组
   var myDate=new Date();//创建一个时间对象
   myDate.setFullYear(eval(begint[0]));//赋年
   myDate.setMonth(eval(begint[1])-1);//赋月,注意date类型的1月是从0开始的，即12月其实是11
   myDate.setDate(eval(begint[2]));//赋日
   
   //parseInt()的用法,如果类似7YY,12MM,-12MM，直接返回数字,支持负数;如果类似YY,Y7Y,返回NaN
   if(diff.indexOf("YY") > 0){//如果间隔是年
      myDate.setFullYear(myDate.getFullYear()+parseInt(diff));
   }else if(diff.indexOf("MM") > 0){//如果间隔是月
      myDate.setMonth(myDate.getMonth()+parseInt(diff));
   }else if(diff.indexOf("DD") > 0){//如果间隔是日
      myDate.setDate(myDate.getDate()+parseInt(diff));
   }else if(diff.indexOf("WW") > 0){//如果间隔是周
      myDate.setDate(myDate.getDate()+7*parseInt(diff));
   }else{//其他情况,不操作,直接返回开始时间
      return begintime;
   }
   return ""+myDate.getFullYear()+"-"+(myDate.getMonth()+1)+"-"+myDate.getDate();//getMonth()获得的月份要+1才是实际显示的月份
}

function saveCode(obj,filename) {
   if(document.getElementById(obj) != null){
      var myDate=new Date();//创建一个时间对象
      var timestr = ""+myDate.getFullYear()+(myDate.getMonth()+1)+myDate.getDate();
      filename = timestr+"_"+filename;

      var tmp_value=document.getElementById(obj);
      var winname = window.open(""+filename+"",'_blank','top=10000,width=800');
      with(winname){
         document.write(tmp_value.innerHTML);
         document.execCommand('Saveas',false,filename);
         close();
      }
          
      //var winname = window.open('', '_blank', 'top=10000'); 
      //var strHTML = document.all.tableExcel.innerHTML; 
          
      /*
      var strHTML = tmp_value.innerHTML;
      winname.document.open('text/html', 'replace'); 
      winname.document.writeln(strHTML);
      winname.document.execCommand("SaveAs",false,filename);
      winname.close(); 
      */
   }else{
      alert("无信息，导出失败！");
   }
}

function TransQuestionToHtml(divname,id,name,descr,controltype,qvalue,showflag,csstype,ifflag,jscheck,setgotoinfo,ifparent,showdescr){//div名称,问题编号，控件名称，提示性文字，控件类型，控件值，横排竖排方式，css样式名称，必填标志，js代码,卷内跳转设置,是否父目录,是否显示备注答案(仅限单选或多选题)
   if(name == "null"){name = "";}
   if(descr == "null"){descr = "";}
   if(controltype == "null"){controltype = "";}
   if(qvalue == "null"){qvalue = "";}
   if(showflag == "null"){showflag = "";}
   if(csstype == "null"){csstype = "form";}//如果无样式,默认用form
   if(ifflag == "null"){ifflag = "";}
   if(jscheck == "null"){jscheck = "";}
   if(setgotoinfo == "null"){setgotoinfo = "";}
   if(ifparent == "null"){ifparent = "";}
   if(showdescr == "null"){showdescr = "";}
   
   var calculateFlag = "";//计分Javascript函数
   var calproperty = "";//计分属性
   if(ifparent != "1"){//如果不是父菜单,则有计分函数，并且该控件有计分属性
      calculateFlag = "Calculate();";
      calproperty = "calproperty=\"1\"";
   }
   
   var JsCodeDiy = "";//一些比较难搞的个性化JS验证,比如说录音质检里4个致命单选问题要归为一个组

   if(name == "c10" || name == "c13" || name == "c36" || name == "c42"){
      //JsCodeDiy = "selectMultiOne(this);";
   }
   if("c441" == name){
      JsCodeDiy = "sendCheckToDiv('c441','q16value');";
   }

   var innerstr = "";//将问题转换成html代码
   
   //var ques_sid = id+"、";//自动给每道问题加编号
   var ques_sid = "";//不自动给每道问题加编号
   
   var answerdescr = "";//应辽宁联通的需求,每道问题增加一个增加备注信息的按钮 by qinli 20090909
   //answerdescr = "<input type=button class=button12 name=descr value=填写备注 onclick=\"addAnswerDescr(questionForm.action,'"+name+"')\">";

   if(csstype.length <= 0){csstype = "form2";}//如果控件无css样式，则默认为form2
   
   var mustinput = "";//必填提示
   if(ifflag == "1")
   {
      mustinput = "<font color=#FF0000> * </font>";
      if(document.getElementById("checkifflag") != null){
         document.getElementById("checkifflag").innerHTML = document.getElementById("checkifflag").innerHTML+"/"+name+"*"+controltype;
      }
   }
   
   if(setgotoinfo.length > 0 && setgotoinfo != "null"){//如果有卷内跳转设置
      if(document.getElementById("setgoto") != null){
         document.getElementById("setgoto").innerText = document.getElementById("setgoto").innerText+"/"+name+"*"+setgotoinfo;
      }
   }

   var boldStyle = "";
   if("1" == ifparent){//父问题需要加粗显示
      boldStyle = " class=boldbig";//
   }
   if("prompt" == controltype){//如果是提示性文字,
   	  boldStyle = " class=boldprompt";//提示语自动加粗加大
   }

   
   var showdiff = "";//横排竖排显示间隔方式
   if(showflag == "1"){//竖排
      showdiff = "<br>";
   }else{//横排
      showdiff = "&nbsp;";
   }
   
   if(document.getElementById(divname) != null){//如果div对象不为空
      switch(controltype){
         case "text":
            //alert("创建单行文本框");
            innerstr = ques_sid + mustinput + descr + showdiff + "<input type=text class="+csstype+" id="+name+" name="+name+">";
            //alert(innerstr);
            innerstr = "<div id=anchor_"+name+" "+boldStyle+">"+innerstr + answerdescr +"</div>";//在innerstr外封装一个锚点
            document.getElementById(divname).innerHTML = innerstr;

            //如果该对象需要js验证
            if(jscheck.length >0){
               if(document.getElementById("checkjscheck") != null){
                  document.getElementById("checkjscheck").innerHTML = document.getElementById("checkjscheck").innerHTML+"/"+name+"*"+jscheck;
               }
            }
            break;
         case "textarea":
            //alert("创建多行文本框");
            innerstr = ques_sid + mustinput + descr + showdiff + "<textarea class="+csstype+" id="+name+" name="+name+" cols=80 rows=3></textarea>";
            //alert(innerstr);
            innerstr = "<div id=anchor_"+name+" "+boldStyle+">"+innerstr + answerdescr+"</div>";//在innerstr外封装一个锚点
            document.getElementById(divname).innerHTML = innerstr;

            //如果该对象需要js验证
            if(jscheck.length >0){
               if(document.getElementById("checkjscheck") != null){
                  document.getElementById("checkjscheck").innerHTML = document.getElementById("checkjscheck").innerHTML+"/"+name+"*"+jscheck;
               }
            }
            break;
         case "radio":
            //alert("创建Radio单选框");
            innerstr = ques_sid + mustinput + descr;
            innerstr = "<span style=\"width:100%;\">" + innerstr + "</span>" + showdiff;
            qvaluearr = qvalue.split("&#&");
            for(var i=0;i<qvaluearr.length;i++){//遍历单选框的值
               innerstr += "<input type=radio id="+name+" name="+name+" "+calproperty+" value="+qvaluearr[i]+" onclick=\""+calculateFlag+JsCodeDiy+"setGoto('"+name+"','"+i+"') \">"+qvaluearr[i]+showdiff;
            }
            if("1" == showdescr){//如果要求加其他答案
               innerstr += "<input type=radio id="+name+" name="+name+" value=其他答案>其他答案:<input type=text class="+csstype+" id="+name+"descr name="+name+"descr>"+showdiff;
            }
            //alert(innerstr);
            innerstr = "<div id=anchor_"+name+" "+boldStyle+">"+innerstr + answerdescr+"</div>";//在innerstr外封装一个锚点
            document.getElementById(divname).innerHTML = innerstr;
            break;
         case "checkbox":
            //alert("创建Checkbox多选框");
            innerstr = ques_sid + mustinput + descr;
            innerstr = "<span style=\"width:100%;\">" + innerstr + "</span>" + showdiff;
            qvaluearr = qvalue.split("&#&");
            for(var i=0;i<qvaluearr.length;i++){//遍历多选框的值
               innerstr += "<input type=checkbox id="+name+" name="+name+" value="+qvaluearr[i]+">"+qvaluearr[i]+showdiff;
            }
            if("1" == showdescr){//如果要求加其他答案
               innerstr += "<input type=checkbox id="+name+" name="+name+" value=其他答案>其他答案:<input type=text class="+csstype+" id="+name+"descr name="+name+"descr>"+showdiff;
            }
            //alert(innerstr);
            innerstr = "<div id=anchor_"+name+" "+boldStyle+">"+innerstr + answerdescr +"</div>";//在innerstr外封装一个锚点
            document.getElementById(divname).innerHTML = innerstr;
            break;
         case "select":
            //alert("创建下拉框");
            innerstr = ques_sid + mustinput + descr;
            innerstr = "<span style=\"width:70%;\">" + innerstr + "</span>" + showdiff;
            innerstr = innerstr + "<select class="+csstype+" id="+name+" name="+name+" "+calproperty+" onChange=\""+calculateFlag+"\">";
            //innerstr += "<option value=>请选择</option>";
            qvaluearr = qvalue.split("&#&");
            for(var i=0;i<qvaluearr.length;i++){//遍历下拉框的值
               innerstr += "<option value="+qvaluearr[i]+">"+qvaluearr[i]+"</option>";
            }
            innerstr += "</select>";
            //alert(innerstr);
            innerstr = "<div id=anchor_"+name+" "+boldStyle+">"+innerstr + answerdescr +"</div>";//在innerstr外封装一个锚点
            document.getElementById(divname).innerHTML = innerstr;
            break;
         case "prompt":
            //alert("创建提示性文字");
            //innerstr = ques_sid + mustinput + descr;
            innerstr = ques_sid + descr;
            //innerstr = "<span style=\"width:99%;\">" + innerstr + "</span>" + showdiff;//提示性文字不需要加showdiff
            innerstr = "<span style=\"width:99%;\">" + innerstr + "</span>";//提示性文字不需要加showdiff
            //alert(innerstr);
            innerstr = "<div id=anchor_"+name+" "+boldStyle+">"+innerstr + answerdescr +"</div>";//在innerstr外封装一个锚点
            document.getElementById(divname).innerHTML = innerstr;
            break;
         default:
            alert("不支持此控件");
      }
   }else{
      alert("你叫我怎么显示出来啊");
   }
}

//检测卷内跳转
function setGoto(seq,num){
   //alert("我去找卷内跳转去啦");
   //alert(seq+" "+num);
   if(document.getElementById("setgoto") != null){
      //alert("所有跳转设置："+document.getElementById("setgoto").innerText);
      var all_setgoto = document.getElementById("setgoto").innerText;
      if(all_setgoto.indexOf(seq+"*") >= 0){//如果找到了相关的设置，那么就去遍历所有跳转设置
         var setgoto_arr = all_setgoto.split("/");
         for(var i=0;i<setgoto_arr.length;i++){
            if(setgoto_arr[i].indexOf(seq+"*") >= 0){
               //alert("总算找到你了："+setgoto_arr[i]);
               var setgoto_one = setgoto_arr[i].replace(seq+"*","");
               
               var setgoto_onearr = setgoto_one.split("&#&");
               if(setgoto_onearr.length >num){
                  //alert("跳转到问题编号"+setgoto_onearr[num]);
                  window.location.hash = "anchor_"+setgoto_onearr[num];
                  changeAnchorBgcolor("anchor_"+setgoto_onearr[num],'0');
               }
            }
         }
      }
   }
}

//改变锚点背景色
function changeAnchorBgcolor(authorname,Colornum){
   //alert("渐变颜色");
   var timediff = 20;
   if(document.getElementById(authorname) != null){
   	  //alert("我要去改变颜色啦");
   	  var color_arr = new Array(16);
   	  color_arr[0] = "0";
   	  color_arr[1] = "1";
   	  color_arr[2] = "2";
   	  color_arr[3] = "3";
   	  color_arr[4] = "4";
   	  color_arr[5] = "5";
   	  color_arr[6] = "6";
   	  color_arr[7] = "7";
   	  color_arr[8] = "8";
   	  color_arr[9] = "9";
   	  color_arr[10] = "A";
   	  color_arr[11] = "B";
   	  color_arr[12] = "C";
   	  color_arr[13] = "D";
   	  color_arr[14] = "E";
   	  color_arr[15] = "F";
   	  
   	  Colornum++;
          Colornum++;
          Colornum++;
   	  if(Colornum > 255){Colornum = 255;}
   	  
   	  var color1 = ""+color_arr[Math.floor(Colornum/16)]+color_arr[Colornum%16];
   	  //var bgColor = "#"+color1+color1+color1;
   	  var bgColor = "#FF"+color1+color1;
   	  
          document.getElementById(authorname).style.background = bgColor;
          if(Colornum < 255){
             setTimeout("changeAnchorBgcolor('"+authorname+"','"+Colornum+"')",timediff);
          }
   }
}

function addAnswerDescr(action,cid){
	 var formAction = action;
         formAction = formAction.substring(0,formAction.indexOf("method"))+"method=addAnswerDescr";
	 //formAction = formAction.replace('votequestion','addAnswerDescr');
	 formAction = formAction + "&cid="+cid;
         window.open (formAction,'_blank','height=250,width=400,top=150,left=300,toolbar=no,menubar=no,scrollbars=no,resizable=no,loocation=no,status=no');
}

//计分系统
function Calculate(){
   if(document.getElementById("scores") != null && document.getElementById("scoreflag") != null){
      var scoreflag = document.getElementById("scoreflag").value;//0为不评分系统,1为加分系统,2为减分系统
      if(scoreflag == "1" || scoreflag == "2"){//只有是加分或减分系统，才执行如下运算
         var scores = document.getElementById("scores").value;//获取原始分数
         if(ifDigit(scores) == false){alert("原始分数不是数字,计分系统失效!");return false;}
         
         scores = parseInt(scores,10);//将字符串转成数字
         
         var form = document.forms[0];
         if(form != null && form.elements != null && form.elements.length > 0){
            for(var i = 0;i<form.elements.length;i++){
               if(form.elements[i].calproperty != null && form.elements[i].calproperty == "1"){//如果该控件属于小类，也就是有calproperty属性
                  if(form.elements[i].type =="radio" && form.elements[i].checked == true){//如果控件是单选框并且被选中
                     var onescore= form.elements[i].value;
                     if(ifDigit(onescore) == true){//如果是数字,则开始计算,否则不计算
                        if(scoreflag == "1"){//加分系统
                           scores = scores + parseInt(onescore,10);
                        }else{//减分系统
                           scores = scores - parseInt(onescore,10);
                        }
                     }
                  }else if(form.elements[i].type =="select-one"){//如果是下拉列表
                     var onescore= form.elements[i].value;
                     if(ifDigit(onescore) == true){//如果是数字,则开始计算,否则不计算
                        if(scoreflag == "1"){//加分系统
                           scores = scores + parseInt(onescore,10);
                        }else{//减分系统
                           scores = scores - parseInt(onescore,10);
                        }
                     }
                  }
               }
            }
            document.getElementById("nowscores").value = scores;//将最新计算结果显示出来
         }else{
            //alert("计分系统不能使用");
         }
      }
   }
}

function ExecJsCheck(str){
   var jscheckstr = str;
   jscheckstr += "*";//防止溢出，末尾加个*号
   var jscheckArr = jscheckstr.split("*");
   //jscheckArr[0]是表单控件名,jscheckArr[1]是要验证的函数
   if(document.getElementById(jscheckArr[0]) != null){
      if(document.getElementById(jscheckArr[0]).value.length > 0){//如果输入的控件有值，则进行判断
         if(jscheckArr[1] == "ifUnicom"){//如果是验证联通号码
            var result = ifUnicom(document.getElementById(jscheckArr[0]).value);
            if(result == false){
               alert("请输入联通号码");
               document.getElementById(jscheckArr[0]).focus();
            }
            return result;
         }else if(jscheckArr[1] == "ifDigit"){//如果是验证数字
            var result = ifDigit(document.getElementById(jscheckArr[0]).value);
            if(result == false){
               alert("请输入数字");
               document.getElementById(jscheckArr[0]).focus();
            }
            return result;
         }else{
            alert("找不到JS函数:"+jscheckArr[1]);
            return false;
         }
      }else{
         return true;
      }
   }else{
      alert("找不到对象");
   }
}



//检查是否是有效身份证号码
//
function checkIdcard(idcard){ 
var Errors=new Array( 
"验证通过!", 
"身份证号码位数不对!", 
"身份证号码出生日期超出范围或含有非法字符!", 
"身份证号码校验错误!", 
"身份证地区非法!" 
); 
var area={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"}  
var idcard,Y,JYM; 
var S,M; 
var idcard_array = new Array(); 
idcard_array = idcard.split(""); 
//地区检验 
if(area[parseInt(idcard.substr(0,2))]==null) return Errors[4]; 
//身份号码位数及格式检验 
switch(idcard.length){ 
case 15: 
if ( (parseInt(idcard.substr(6,2))+1900) % 4 == 0 || ((parseInt(idcard.substr(6,2))+1900) % 100 == 0 && (parseInt(idcard.substr(6,2))+1900) % 4 == 0 )){ 
ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$/;//测试出生日期的合法性 
} else { 
ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$/;//测试出生日期的合法性 
} 
if(ereg.test(idcard)) return Errors[0]; 
else return Errors[2]; 
break; 
case 18: 
//18位身份号码检测 
//出生日期的合法性检查  
//闰年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9])) 
//平年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8])) 
if ( parseInt(idcard.substr(6,4)) % 4 == 0 || (parseInt(idcard.substr(6,4)) % 100 == 0 && parseInt(idcard.substr(6,4))%4 == 0 )){ 
ereg=/^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$/;//闰年出生日期的合法性正则表达式 
} else { 
ereg=/^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$/;//平年出生日期的合法性正则表达式 
} 
if(ereg.test(idcard)){//测试出生日期的合法性 
//计算校验位 
S = (parseInt(idcard_array[0]) + parseInt(idcard_array[10])) * 7 
+ (parseInt(idcard_array[1]) + parseInt(idcard_array[11])) * 9 
+ (parseInt(idcard_array[2]) + parseInt(idcard_array[12])) * 10 
+ (parseInt(idcard_array[3]) + parseInt(idcard_array[13])) * 5 
+ (parseInt(idcard_array[4]) + parseInt(idcard_array[14])) * 8 
+ (parseInt(idcard_array[5]) + parseInt(idcard_array[15])) * 4 
+ (parseInt(idcard_array[6]) + parseInt(idcard_array[16])) * 2 
+ parseInt(idcard_array[7]) * 1  
+ parseInt(idcard_array[8]) * 6 
+ parseInt(idcard_array[9]) * 3 ; 
Y = S % 11; 
M = "F"; 
JYM = "10X98765432"; 
M = JYM.substr(Y,1);//判断校验位 
if(M == idcard_array[17]) return Errors[0]; //检测ID的校验位 
else return Errors[3]; 
} 
else return Errors[2]; 
break; 
default: 
return Errors[1]; 
break; 
} 
} 

//用户的生日，是否是身份证号的生日一致
//by cc
function checkBirth4Id(birth,idcard){
	
    arBirth=	birth.replace(/-/g,"");
	if (arBirth.length==0 )
	{
		return "ok";
	}
	switch(idcard.length){ 
	case 15: 
	 		if (idcard.substr(6,6)!=arBirth.substr(2,6))
	     return "您选择的生日与身份证号码中的生日不一致!";	 
			 break;
	case 18: 
			if (idcard.substr(6,8)!=arBirth)	   
	    return "您选择的生日与身份证号码中的生日不一致!";
	 		break;
   default:
       return "您的生日格式有误";
       break;
	 } 
   return "ok";
}

//检查是否是有效身份证号码,并是否与生日一致
//by cc
function checkIdcard2Birth(birth,idcard){
	 //1.用户的生日，是否是身份证号的生日一致 
	
	 var ret=checkBirth4Id(birth,idcard);
	 if (ret!="ok")
	 {	 	 
	 	 return ret;
	 	}
	 	//2.检查是否是有效身份证号码
	 	return checkIdcard (idcard);

}


//检查是正确的邮编
//by cc
function  check_ecode(code) 
{
	 
	  if (code.value.length!=6) 
		{ 
		  alert("邮政编码必须等于6位!"); 
		  code.focus(); 
		  return(false); 
		} 
		if (ifDigit(code.value)==false)
	  { 
			alert("邮政编码输入有误,应为数字！");
			code.focus();
			return false;
		
		}
		
		if (code.value=="200000")
		{
			alert("邮政编码输入有误,不能输入200000");
			code.focus();
			return false;
		}
		
		return true;
		

}
//检测时间格式
function CheckTimeFormat(timestr){
   if(timestr.length < 8){return "时间格式不正确！";}
   if(timestr.length > 10){return "时间格式不正确！";}
   
   timerarr = timestr.split("-");
   if(timerarr.length != 3){return "时间格式不正确！！";}
   return true;
}
//检测时间内容,例如2009-11-10
function CheckTimeContent(timestr){
   var timeyear = "";
   var timemonth = "";
   var timeday = "";
   var timevalue = "";
   timerarr = timestr.split("-");
   if(timerarr.length != 3){
      return "时间格式不正确";
   }
   
   timeyear = timerarr[0];
   if(timeyear.length != 4){return "请输入4位年份";}
   
   if(timerarr[1].length <= 0){
      return "月份输入不正确";
   }else if(timerarr[1].length == 1){
      timemonth = "0" + timerarr[1];
   }else if(timerarr[1].length == 2){
      timemonth = timerarr[1];
   }else{
      return "月份输入不正确";
   }
   
   if(timerarr[2].length <= 0){
      return "日期输入不正确";
   }else if(timerarr[2].length == 1){
      timeday = "0" + timerarr[2];
   }else if(timerarr[2].length == 2){
      timeday = timerarr[2];
   }else{
      return "日期输入不正确";
   }
   
   if(ifDigit(timeyear) == false){return "年份含非数字字符";}
   if(ifDigit(timemonth) == false){return "月份含非数字字符";}
   if(ifDigit(timeday) == false){return "日期含非数字字符";}
   
   if(parseInt(timemonth,10) > 12){return "月份不正确";}
   if(parseInt(timemonth,10) <= 0){return "月份不正确";}
   if(parseInt(timeday,10) > 31){return "日期不正确";}
   if((parseInt(timemonth,10) == 4 || parseInt(timemonth,10) == 6 || parseInt(timemonth,10) == 9 || parseInt(timemonth,10) == 11) && parseInt(timeday,10) > 30){return "日期不正确";}//判断小月的日期不能大于30
   if(parseInt(timemonth,10) == 2 && parseInt(timeday,10) > 29){return "日期不正确";}
   if(parseInt(timemonth,10) == 2 && parseInt(timeday,10) == 29){//如果是2月29日，则判断是否闰年
      if(parseInt(timeyear,10) % 4 != 0 || (parseInt(timeyear,10) % 100 == 0 && parseInt(timeyear,10) % 400 != 0)){//不是闰年
         return "日期不正确";
      }
   }
   
   timevalue = timeyear + timemonth + timeday;
   if(timevalue.length != 8){return "时间格式不正确!";}
   return true;
}
//检测时间内容例如10:20
function CheckTimeContent2(timestr){
   var timeHour = "";
   var timeMinute = "";
   timerarr = timestr.split(":");

   if(timerarr.length != 2){
      return "时间格式不正确";
   }

   timeHour = timerarr[0];//小时
   timeMinute = timerarr[1];//分钟

   if(timeHour.length <= 0){
      return "请输入正确的时间";
   }else if(timeHour.length == 1){
      timeHour = "0" + timeHour;
   }else if(timeHour.length == 2){
      timeHour = timeHour;
   }else{
      return "时间输入不正确";
   }
   
   if(timeMinute.length <= 0){
      return "请输入正确的时间";
   }else if(timeMinute.length == 1){
      timeMinute = "0" + timeMinute;
   }else if(timeMinute.length == 2){
      timeMinute = timeMinute;
   }else{
      return "时间输入不正确";
   }
   
   if(ifDigit(timeHour) == false){return "时间含非数字字符";}
   if(ifDigit(timeMinute) == false){return "时间含非数字字符";}
   
   if(parseInt(timeHour,10) > 23){return "小时数不能大于23";}
   if(parseInt(timeMinute,10) > 59){return "分钟数不能大于59";}

   return true;
}
//检测时间控件输入是否正确
function checktime(obj){
   if(obj.value.length > 0){
      if(CheckTimeFormat(obj.value) != true){
         alert(CheckTimeFormat(obj.value));
         obj.value = "";
         obj.focus();
      }else{
         if(CheckTimeContent(obj.value) != true){
            alert(CheckTimeContent(obj.value));
            obj.value = "";
            obj.focus();
         }
      }
   }
}
//删除sel下的所有对象
 function DelSelOption(selObject){
	var i =selObject.length;
	for(var j=i-1;j>=0;j--){
	   selObject.remove(j);
	}
 } 
 //将时间格式化
 function timeFormats(strTime,flag){	
	var starttime_tmp = strTime.split("-");
    if(starttime_tmp[1].length <2)
    	starttime_tmp[1] = "0" + starttime_tmp[1];
    if(starttime_tmp[2].length <2)
    	starttime_tmp[2] = "0" + starttime_tmp[2];
    var thisTime = "";
    switch(flag){
    case 0:
    	//格式化为yyyy-MM-dd HH:mm:ss (yyyy-MM-dd 00:00:00)
    	thisTime = starttime_tmp[0] + "-" + starttime_tmp[1] + "-" + starttime_tmp[2] + " 00:00:00";
    	break;
    case 1:
    	//格式化为yyyy-MM-dd HH:mm:ss (yyyy-MM-dd 23:59:59)
    	thisTime = starttime_tmp[0] + "-" + starttime_tmp[1] + "-" + starttime_tmp[2] + " 23:59:59";
    	break;
    default:
    	thisTime = starttime_tmp[0] + starttime_tmp[1] + starttime_tmp[2];
    	break;
    }
    return thisTime;
}

//从多个不同的radio对象中关联只能选择1个
function selectMultiOne(obj){
   objName = "c10;c13;c36;c42";
   if(objName.length > 0){
      var objArray = objName.split(";");
      for(var i=0;i<objArray.length;i++){
         if(document.getElementsByName(objArray[i]) != null && document.getElementsByName(objArray[i]).length > 0){//确定对象存在
            var objs = document.getElementsByName(objArray[i]);
            for(var j=0;j<objs.length;j++){
               if(objs[j].type == "radio"){
                  objs[j].checked = false;
               }
            }
         }
      }
   }
   obj.checked = true;
}
//将该题选中的结果在另一标签显示出来
function sendCheckToDiv(objname,divname){
	 var objs = document.getElementsByName(objname);
	 var objvalue = "";
   for(var j=0;j<objs.length;j++){
       if(objs[j].type == "radio" && objs[j].checked == true){
          objvalue = objs[j].value;
          break;
       }
   }
   //如果有选中值,且要提示的div标签存在
   if(objvalue.length > 0 && document.getElementById(divname) != null){
      document.getElementById(divname).innerHTML = "<font color=#FF0000><b>Q16题选中:"+objvalue+"</b></font>";
   }
}
//关键字高亮显示
function findKeyWord(keyword)
{
    keyword=keyword.replace(/^ +| +$/g, "");
    keyword=keyword.replace(/ +/g, " ");
    
    if(keyword=="") return;
    var r = document.body.createTextRange(); //创建文本对象
    while (r.findText(keyword)) { //查找关键字
        r.execCommand('BackColor', '', '#ff4'); //背景色
        r.execCommand('ForeColor', '', 'red');  //前景色
        r.collapse(false);
    }
}

//截取知识库帖子部分内容
function promptContent(sid,keyword){
   //var content = document.getElementById("divOld"+sid).value.replace(/\"/g," ");//替换双引号
   var content = document.getElementById("divOld"+sid).innerText.replace(/\r\n/g," ");//替换换行符
   var beginPos = 0;
   var endPos = 100;
   var leftPoint = "";//左边省略号
   var rightPoint = "...";//右边省略号
   
   if(content.length < 100){
      endPos = content.length;
      rightPoint = "";
   }else if(keyword.length > 0 && content.indexOf(keyword) >= 0){
      beginPos = content.indexOf(keyword)-10;
      endPos = content.indexOf(keyword)+90;
      leftPoint = "...";
      rightPoint = "...";
      if(beginPos <=0){
         beginPos = 0;
         endPos = 100;
         leftPoint = "";
         rightPoint = "...";
      }else if(content.length < endPos){
         endPos = content.length;
         beginPos = content.length-100;
         leftPoint = "...";
         rightPoint = "";
      }
   }
   
   document.getElementById("divNew"+sid).innerHTML = leftPoint+content.substring(beginPos,endPos)+rightPoint;
}
//弹开新页面
function newWindow(url,width,height){
   var winWidth = window.screen.width;
   var winHeight = window.screen.height;
   window.open (url,'_blank','height='+height+',width='+width+',top='+(winHeight-height-80)/2+',left='+(winWidth-width)/2+',toolbar=no,menubar=no,scrollbars=yes,resizable=yes,loocation=no,status=yes');
}
//随机值
function RandomNum(num)
{
    var temp = "";
    var i = 0;
    for(i=0;i<num;i++)
    {
		var allStr = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";   
		var sp = allStr.split("");   
		var n = Math.round(Math.random() * sp.length);
		temp = sp[n] + temp;
	}
	if(temp.length != num) temp = RandomNum(num);
	return temp;
}
//获取yyyyMMddhhmmss
function getCtime(){
   var myDate=new Date();
   myDate.getFullYear()+(myDate.getMonth()+1)+myDate.getDate();
   var yyyy = ""+myDate.getFullYear();
   var MM = ""+(myDate.getMonth()+1);
   if(MM.length <= 1){MM = "0"+MM;}
   var dd = ""+myDate.getDate();
   if(dd.length <= 1){dd = "0"+dd;}
   var hh = ""+myDate.getHours();
   if(hh.length <= 1){hh = "0"+hh;}
   var mm = ""+myDate.getMinutes();
   if(mm.length <= 1){mm = "0"+mm;}
   var ss = ""+myDate.getSeconds();
   if(ss.length <= 1){ss = "0"+ss;}
   
   return yyyy+MM+dd+hh+mm+ss;
}
//获取yyyy-MM-dd hh:mm:ss
function getCtime2(){
   var myDate=new Date();
   myDate.getFullYear()+(myDate.getMonth()+1)+myDate.getDate();
   var yyyy = myDate.getFullYear();
   var MM = ""+(myDate.getMonth()+1);
   if(MM.length <= 1){MM = "0"+MM;}
   var dd = ""+myDate.getDate();
   if(dd.length <= 1){dd = "0"+dd;}
   var hh = ""+myDate.getHours();
   if(hh.length <= 1){hh = "0"+hh;}
   var mm = ""+myDate.getMinutes();
   if(mm.length <= 1){mm = "0"+mm;}
   var ss = ""+myDate.getSeconds();
   if(ss.length <= 1){ss = "0"+ss;}
   
   return yyyy+"-"+MM+"-"+dd+" "+hh+":"+mm+":"+ss;
}
//返回流水号yyyyMMddhhmmss+2位随机，共16位
function getLSH(){
   return getCtime()+RandomNum(2);
}
//显示div
function showDiv(divname,obj){
	 //alert(getAbsoluteTop(obj)+"/"+getAbsoluteLeft(obj));
   if(document.getElementById(divname) != null){
   	  if(obj != null){
         document.getElementById(divname).style.top = getAbsoluteTop(obj) + 20;
         document.getElementById(divname).style.left = getAbsoluteLeft(obj);
   	  }
   	  document.getElementById(divname).style.display='block';
   }
}
//隐藏div
function hideDiv(divname){
   if(document.getElementById(divname) != null){
   	  document.getElementById(divname).style.display='none';
   }
}
//获取对象相对网页横坐标
function getAbsoluteLeft(obj){
   var mendingLeft = obj.offsetLeft;
   while(obj != null && obj.offsetParent != null && obj.offsetParent.tagName != "BODY"){
      mendingLeft += obj.offsetParent.offsetLeft;
      obj = obj.offsetParent;
   }
   return mendingLeft;
}
//获取对象相对网页纵坐标
function getAbsoluteTop(obj){
   var mendingTop = obj.offsetTop;
   while(obj != null && obj.offsetParent != null && obj.offsetParent.tagName != "BODY"){
      mendingTop += obj.offsetParent.offsetTop;
      obj = obj.offsetParent;
   }
   return mendingTop;
}
//隐藏或显示obj对象
function showOrHide(obj){
   if(document.getElementById(obj) != null){
      if(document.getElementById(obj).style.display == "none"){
         document.getElementById(obj).style.display = "block";
      }else{
         document.getElementById(obj).style.display = "none";
      }
   }
}
//批准坐席示忙请求
function checkAgentBusy(status){
   //status=1表示允许，2为拒绝
   var sequenceid = agentseq.value;
   if(sequenceid.length > 0){
      document.getElementById("ifrbusy").src="${pageContext.request.contextPath}/agent.do?method=checkBusy&sequenceid="+sequenceid+"&status="+status+"&ss="+RandomNum(2);
      document.getElementById('checkbusy').style.visibility='hidden';
   }
}

//显示进度条
function showProcessBar(){
   try{
      //var scrWidth = window.screen.width;
      var pageWidth = document.body.offsetWidth;
      document.getElementById("processbar").style.left = (pageWidth-document.getElementById("processbar").offsetWidth)/2;
      showIframeMask("processbar");//显示Iframe蒙板,防止select盖住div层
      document.getElementById("processbar").style.visibility = "visible";
   }catch(e){
      alert("显示加载条失败:"+e.description);
   }
}
//隐藏进度条
function hideProcessBar(){
   try{
      document.getElementById("processbar").style.visibility = "hidden";
      hideIframeMask();
   }catch(e){
      alert("隐藏加载条失败:"+e.description);
   }
}

//显示蒙板
function showIframeMask(obj){
   try{
      if(document.getElementById("iframeMask") != null){
         document.getElementById("iframeMask").style.width = document.getElementById(obj).offsetWidth;
         document.getElementById("iframeMask").style.height = document.getElementById(obj).offsetHeight;
         document.getElementById("iframeMask").style.top = document.getElementById(obj).style.top;
         document.getElementById("iframeMask").style.left = document.getElementById(obj).style.left;
         document.getElementById("iframeMask").style.zIndex = document.getElementById(obj).style.zIndex-1;
         document.getElementById("iframeMask").style.visibility='visible';
      }
   }catch(e){
      alert("显示加载条蒙板失败:"+e.description);
   }
}
//关闭蒙板
function hideIframeMask(){
   try{
      if(document.getElementById("iframeMask") != null){
         document.getElementById("iframeMask").style.visibility='hidden';
      }
   }catch(e){
      alert("隐藏加载条蒙板失败:"+e.description);
   }
}

//获取控件相对本页面的绝对横坐标
function getElementViewLeft(element){
   var actualLeft = element.offsetLeft;
   var current = element.offsetParent;

   while (current !== null){
      actualLeft += current.offsetLeft;
      current = current.offsetParent;
   }

   if (document.compatMode == "BackCompat"){
      var elementScrollLeft=document.body.scrollLeft;
   }else{
      var elementScrollLeft=document.documentElement.scrollLeft; 
   }
   return actualLeft-elementScrollLeft;
}
//获取控件相对本页面的绝对纵坐标
function getElementViewTop(element){
   var actualTop = element.offsetTop;
   var current = element.offsetParent;

   while (current !== null){
      actualTop += current. offsetTop;
      current = current.offsetParent;
   }

   if (document.compatMode == "BackCompat"){
      var elementScrollTop=document.body.scrollTop;
   } else {
      var elementScrollTop=document.documentElement.scrollTop; 
   }

   return actualTop-elementScrollTop;
}

//获取当前系统时间,返回yyyy-mm-dd
function getYYYYMMDD(){
   var myDate=new Date();
   myDate.getFullYear()+(myDate.getMonth()+1)+myDate.getDate();
   var yyyy = ""+myDate.getFullYear();
   var MM = ""+(myDate.getMonth()+1);
   if(MM.length <= 1){MM = "0"+MM;}
   var dd = ""+myDate.getDate();
   if(dd.length <= 1){dd = "0"+dd;}
   
   return yyyy+"-"+MM+"-"+dd;
}
//获取当天系统时间提前(XX年,XX月,XX日)的日期,返回格式yyyy-mm-dd
function getYYYYMMDDbefore(year,month,day){
   var myDate=new Date();
   if(year > 0){
      myDate.setFullYear(myDate.getFullYear()-parseInt(year,10));
   }
   if(month > 0){
      myDate.setMonth(myDate.getMonth()-parseInt(month,10));
   }
   if(day > 0){
      myDate.setDate(myDate.getDate()-parseInt(day,10));
   }
   if(day < 0){
      myDate.setDate(myDate.getDate()-parseInt(day,10));
   }
   var yyyy = ""+myDate.getFullYear();
   var MM = ""+(myDate.getMonth()+1);
   if(MM.length == 0){MM = "0"+MM;}
   if(MM.length == 1){MM = "0"+MM;}
   var dd = ""+myDate.getDate();
   if(dd.length == 0){dd = "0"+dd;}
   if(dd.length == 1){dd = "0"+dd;}
   
   return yyyy+"-"+MM+"-"+dd;
}

function getCtimeYYYYMMDD(){
   //返回当前系统时间,格式为yyyymmdd
   var myDate=new Date();//创建一个时间对象
   
   var yyyy = "" + myDate.getFullYear();
   
   var mm = "" + (myDate.getMonth()+1);
   if(mm.length == 1){
      mm = "0" + mm;
   }
   
   var dd = "" + myDate.getDate();
   if(dd.length == 1){
      dd = "0" + dd;
   }
   
   return yyyy+"-"+mm+"-"+dd;
}

function getDiffTime2(begintime,diff)
{
   
   var begint = begintime.split("-");
   var myDate=new Date();
   myDate.setFullYear(eval(begint[0]));
   myDate.setMonth(eval(begint[1])-1);
   myDate.setDate(eval(begint[2]));
   
  
   if(diff.indexOf("YY") > 0){
      myDate.setFullYear(myDate.getFullYear()+parseInt(diff));
   }else if(diff.indexOf("MM") > 0){
      myDate.setMonth(myDate.getMonth()+parseInt(diff));
   }else if(diff.indexOf("DD") > 0){
      myDate.setDate(myDate.getDate()+parseInt(diff));
   }else if(diff.indexOf("WW") > 0){
      myDate.setDate(myDate.getDate()+7*parseInt(diff));
   }else{
      return begintime;
   }
   var yyyy = ""+myDate.getFullYear();
   var mm = ""+(myDate.getMonth()+1);
   if(mm.length <= 1){mm = "0" + mm;}
   var dd = ""+myDate.getDate();
   if(dd.length <= 1){dd = "0" + dd;}
   return ""+yyyy+"-"+mm+"-"+dd;
}